package GUI.Administracion;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JComboBox;
import javax.swing.JTextField;
import javax.swing.JScrollPane;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.JButton;

import BBDD.ManageAlumno;
import BBDD.ManageCiclo;
import DAO.CicloDAO;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.Vector;

public class NuevoCiclo extends JFrame {

	private JPanel contentPane;
	private JTextField txtIdCilco;
	private JTable table;
	private ManageCiclo controladorBD;
	private JTextField txtNombreCiclo;	
	private JTextField txtidFamilia;
	

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					NuevoCiclo frame = new NuevoCiclo();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public NuevoCiclo() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 468, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);

		JPanel panel = new JPanel();
		panel.setLayout(null);

		JLabel lbl = new JLabel("Id Ciclo");
		lbl.setBounds(0, 3, 59, 14);
		panel.add(lbl);

		JLabel label_1 = new JLabel("Nombre Ciclo");
		label_1.setBounds(0, 34, 73, 14);
		panel.add(label_1);

		txtIdCilco = new JTextField();
		txtIdCilco.setColumns(10);
		txtIdCilco.setBounds(79, 0, 86, 20);
		panel.add(txtIdCilco);

		JLabel label_2 = new JLabel("Id Familia");
		label_2.setBounds(175, 3, 51, 14);
		panel.add(label_2);

		JScrollPane scrollPane = new JScrollPane();

		JButton btnVolver = new JButton("Volver");
		btnVolver.setIcon(new ImageIcon(NuevoProfesor.class
				.getResource("/Utilidades/volver.png")));
		btnVolver.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				dispose();
			}
		});
		GroupLayout gl_contentPane = new GroupLayout(contentPane);
		gl_contentPane
				.setHorizontalGroup(gl_contentPane
						.createParallelGroup(Alignment.TRAILING)
						.addGroup(
								gl_contentPane
										.createSequentialGroup()
										.addGroup(
												gl_contentPane
														.createParallelGroup(
																Alignment.LEADING)
														.addGroup(
																gl_contentPane
																		.createSequentialGroup()
																		.addContainerGap()
																		.addComponent(
																				panel,
																				GroupLayout.PREFERRED_SIZE,
																				429,
																				GroupLayout.PREFERRED_SIZE))
														.addGroup(
																gl_contentPane
																		.createSequentialGroup()
																		.addContainerGap()
																		.addComponent(
																				scrollPane,
																				GroupLayout.DEFAULT_SIZE,
																				429,
																				Short.MAX_VALUE))
														.addGroup(
																Alignment.TRAILING,
																gl_contentPane
																		.createSequentialGroup()
																		.addContainerGap(
																				333,
																				Short.MAX_VALUE)
																		.addComponent(
																				btnVolver)))
										.addContainerGap()));
		gl_contentPane.setVerticalGroup(gl_contentPane.createParallelGroup(
				Alignment.LEADING).addGroup(
				gl_contentPane
						.createSequentialGroup()
						.addContainerGap()
						.addComponent(panel, GroupLayout.PREFERRED_SIZE, 65,
								GroupLayout.PREFERRED_SIZE)
						.addPreferredGap(ComponentPlacement.RELATED)
						.addComponent(scrollPane, GroupLayout.PREFERRED_SIZE,
								111, GroupLayout.PREFERRED_SIZE)
						.addPreferredGap(ComponentPlacement.UNRELATED)
						.addComponent(btnVolver)
						.addContainerGap(GroupLayout.DEFAULT_SIZE,
								Short.MAX_VALUE)));

		JButton btnGuardar = new JButton("Guardar");
		btnGuardar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				controladorBD = new ManageCiclo();
				String query = "INSERT INTO ciclo VALUES (" + txtIdCilco.getText()
						+ ", " + txtidFamilia.getText() + ", '"
						+ txtNombreCiclo.getText() + "')";

				controladorBD.updateCiclo(query);

			}
		});
		btnGuardar.setBounds(330, 30, 89, 23);
		panel.add(btnGuardar);

		txtNombreCiclo = new JTextField();
		txtNombreCiclo.setBounds(79, 31, 200, 20);
		panel.add(txtNombreCiclo);
		txtNombreCiclo.setColumns(10);
		txtidFamilia = new JTextField();
		txtidFamilia.setBounds(236, 0, 86, 20);
		panel.add(txtidFamilia);
		txtidFamilia.setColumns(10);

		table = new JTable();
		table.setModel(new DefaultTableModel(new Object[][] {
				{ null, null, null }, { null, null, null },
				{ null, null, null }, }, new String[] { "Id Ciclo",
				"Nombre Ciclo", "Id Familia" }));
		scrollPane.setViewportView(table);
		contentPane.setLayout(gl_contentPane);
	}

}
